﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace DnPakExplorer {
	public class WindowsUtil {
		public static void SetFormRoundRectRgn(Form form, int rgnRadius) {
			int hRgn = 0;
			hRgn = Win32.CreateRoundRectRgn(0, 0, form.Width + 1, form.Height + 1, rgnRadius, rgnRadius);
			Win32.SetWindowRgn(form.Handle, hRgn, true);
			Win32.DeleteObject(hRgn);
		}

		private const int WM_SYSCOMMAND = 0x0112;//点击窗口左上角那个图标时的系统信息 
		private const int SC_MOVE = 0xF010;//移动信息 
		private const int HTCAPTION = 0x0002;//表示鼠标在窗口标题栏时的系统信息 
		private const int WM_NCHITTEST = 0x84;//鼠标在窗体客户区（除了标题栏和边框以外的部分）时发送的消息 
		private const int HTCLIENT = 0x1;//表示鼠标在窗口客户区的系统消息 
		private const int SC_MAXIMIZE = 0xF030;//最大化信息 
		private const int SC_MINIMIZE = 0xF020;//最小化信息 

		/// <summary>
		/// 移动窗体
		/// </summary>
		public static void MoveWindow(Form form) {
			Win32.ReleaseCapture();
			//Win32.SendMessage(form.Handle, Win32.WM_NCLBUTTONDOWN, Win32.HTCAPTION, 0);
			Win32.SendMessage(form.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
		}

		/// <summary>
		/// 取低位 X 坐标
		/// </summary>
		public static int LOWORD(int value) {
			return value & 0xFFFF;
		}

		/// <summary>
		/// 取高位 Y 坐标
		/// </summary>
		public static int HIWORD(int value) {
			return value >> 16;
		}

		/// <summary>
		/// 绘制窗体边框
		/// </summary>
		/// <param name="destForm">需要绘制边框的窗体</param>
		/// <param name="g">绘制边框所用的绘图对象</param>
		/// <param name="fringeImg">边框图片</param>
		/// <param name="radius">边框的圆角矩形</param>
		public static void DrawFormFringe(Form destForm, Graphics g, Image fringeImg, int radius) {
			DrawNineRect(
				g,
				fringeImg,
				new Rectangle(-radius, -radius, destForm.ClientSize.Width + 2 * radius, destForm.ClientSize.Height + 2 * radius),
				new Rectangle(0, 0, fringeImg.Width, fringeImg.Height));
		}

		/// <summary>
		/// 画九宫图
		/// </summary>
		/// <param name="g">绘图对象</param>
		/// <param name="img">所需绘制的图片</param>
		/// <param name="DestRect">目标矩形</param>
		/// <param name="SrcRect">来源矩形</param>
		public static void DrawNineRect(Graphics g, Image img, Rectangle DestRect, Rectangle SrcRect) {
			int offset = 5;
			Rectangle NineRect = new Rectangle(img.Width / 2 - offset, img.Height / 2 - offset, 2 * offset, 2 * offset);
			int x = 0, y = 0, nWidth, nHeight;
			int xSrc = 0, ySrc = 0, nSrcWidth, nSrcHeight;
			int nDestWidth, nDestHeight;
			nDestWidth = DestRect.Width;
			nDestHeight = DestRect.Height;
			// 左上-------------------------------------;
			x = DestRect.Left;
			y = DestRect.Top;
			nWidth = NineRect.Left - SrcRect.Left;
			nHeight = NineRect.Top - SrcRect.Top;
			xSrc = SrcRect.Left;
			ySrc = SrcRect.Top;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nWidth, nHeight, GraphicsUnit.Pixel);
			// 上-------------------------------------;
			x = DestRect.Left + NineRect.Left - SrcRect.Left;
			nWidth = nDestWidth - nWidth - (SrcRect.Right - NineRect.Right);
			xSrc = NineRect.Left;
			nSrcWidth = NineRect.Right - NineRect.Left;
			nSrcHeight = NineRect.Top - SrcRect.Top;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nSrcWidth, nSrcHeight, GraphicsUnit.Pixel);
			// 右上-------------------------------------;
			x = DestRect.Right - (SrcRect.Right - NineRect.Right);
			nWidth = SrcRect.Right - NineRect.Right;
			xSrc = NineRect.Right;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nWidth, nHeight, GraphicsUnit.Pixel);
			// 左-------------------------------------;
			x = DestRect.Left;
			y = DestRect.Top + NineRect.Top - SrcRect.Top;
			nWidth = NineRect.Left - SrcRect.Left;
			nHeight = DestRect.Bottom - y - (SrcRect.Bottom - NineRect.Bottom);
			xSrc = SrcRect.Left;
			ySrc = NineRect.Top;
			nSrcWidth = NineRect.Left - SrcRect.Left;
			nSrcHeight = NineRect.Bottom - NineRect.Top;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nSrcWidth, nSrcHeight, GraphicsUnit.Pixel);
			// 中-------------------------------------;
			x = DestRect.Left + NineRect.Left - SrcRect.Left;
			nWidth = nDestWidth - nWidth - (SrcRect.Right - NineRect.Right);
			xSrc = NineRect.Left;
			nSrcWidth = NineRect.Right - NineRect.Left;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nSrcWidth, nSrcHeight, GraphicsUnit.Pixel);

			// 右-------------------------------------;
			x = DestRect.Right - (SrcRect.Right - NineRect.Right);
			nWidth = SrcRect.Right - NineRect.Right;
			xSrc = NineRect.Right;
			nSrcWidth = SrcRect.Right - NineRect.Right;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nSrcWidth, nSrcHeight, GraphicsUnit.Pixel);

			// 左下-------------------------------------;
			x = DestRect.Left;
			y = DestRect.Bottom - (SrcRect.Bottom - NineRect.Bottom);
			nWidth = NineRect.Left - SrcRect.Left;
			nHeight = SrcRect.Bottom - NineRect.Bottom;
			xSrc = SrcRect.Left;
			ySrc = NineRect.Bottom;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nWidth, nHeight, GraphicsUnit.Pixel);
			// 下-------------------------------------;
			x = DestRect.Left + NineRect.Left - SrcRect.Left;
			nWidth = nDestWidth - nWidth - (SrcRect.Right - NineRect.Right);
			xSrc = NineRect.Left;
			nSrcWidth = NineRect.Right - NineRect.Left;
			nSrcHeight = SrcRect.Bottom - NineRect.Bottom;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nSrcWidth, nSrcHeight, GraphicsUnit.Pixel);
			// 右下-------------------------------------;
			x = DestRect.Right - (SrcRect.Right - NineRect.Right);
			nWidth = SrcRect.Right - NineRect.Right;
			xSrc = NineRect.Right;
			g.DrawImage(img, new Rectangle(x, y, nWidth, nHeight), xSrc, ySrc, nWidth, nHeight, GraphicsUnit.Pixel);
		}


		/// <summary>
		/// 绘制窗体主体部分白色透明层
		/// </summary>
		/// <param name="form">需要绘制的窗体</param>
		/// <param name="g">绘图对象</param>
		public static void DrawFromAlphaMainPart(Form form, Graphics g) {
			Color[] colors = 
            {
                Color.FromArgb(5, Color.White),
                Color.FromArgb(30, Color.White),
                Color.FromArgb(150, Color.White),
                Color.FromArgb(180, Color.White),
                Color.FromArgb(30, Color.White),
                Color.FromArgb(5, Color.White)
            };

			float[] pos = 
            {
                0.0f,
                0.05f,
                0.15f,
                0.85f,
                0.99f,
                1.0f      
            };

			ColorBlend colorBlend = new ColorBlend(6);
			colorBlend.Colors = colors;
			colorBlend.Positions = pos;

			RectangleF destRect = new RectangleF(0, 0, form.Width, form.Height);
			using (LinearGradientBrush lBrush = new LinearGradientBrush(destRect, colors[0], colors[5], LinearGradientMode.Vertical)) {
				lBrush.InterpolationColors = colorBlend;
				g.FillRectangle(lBrush, destRect);
			}
		}
	}

	public class DrawingUtil {
		public static void DrawOuterGrowText(Graphics g, Rectangle rect, string text, FontFamily fontFmaily, FontStyle fontStyle, float emSize, Color textColor, Color outerColor, float outerSize, float facter, StringFormat sf) {
			//Create a bitmap in a fixed ratio to the original drawing area.
			Bitmap bm= new Bitmap((int)(rect.Width/facter), (int)(rect.Height/facter));
			//Create a GraphicsPath object. 
			GraphicsPath pth=new GraphicsPath();
			//Add the string in the chosen style. 
			pth.AddString(text, fontFmaily, (int)fontStyle, emSize, new Rectangle(0, 0, rect.Width, rect.Height), sf);
			//Get the graphics object for the image. 
			Graphics tmpG=Graphics.FromImage(bm);
			//Choose an appropriate smoothing mode for the halo. 
			tmpG.SmoothingMode=SmoothingMode.AntiAlias;
			//Create a matrix that shrinks the drawing output by the fixed ratio. 
			//Transform the graphics object so that the same half may be used for both halo and text output. 
			tmpG.Transform=new Matrix(1.0f/facter, 0, 0, 1.0f/facter, 0, 0);
			//Using a suitable pen...
			Pen p=new Pen(outerColor, outerSize);
			//Draw around the outline of the path
			tmpG.DrawPath(p, pth);
			//and then fill in for good measure. 
			tmpG.FillPath(new SolidBrush(outerColor), pth);
			//We no longer need this graphics object
			tmpG.Dispose();
			Matrix oldMatrix = g.Transform;
			//this just shifts the effect a little bit so that the edge isn't cut off in the demonstration
			g.Transform=new Matrix(1, 0, 0, 1, rect.X, rect.Y);
			//setup the smoothing mode for path drawing
			g.SmoothingMode=SmoothingMode.AntiAlias;
			//and the interpolation mode for the expansion of the halo bitmap
			g.InterpolationMode=InterpolationMode.HighQualityBicubic;
			//expand the halo making the edges nice and fuzzy. 
			g.DrawImage(bm, new Rectangle(0, 0, rect.Width, rect.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
			//Redraw the original text
			g.FillPath(new SolidBrush(textColor), pth);
			g.Transform = oldMatrix;
			//and you're done. 
			pth.Dispose();
		}
	}

	[StructLayout(LayoutKind.Sequential)]
	struct NCCalcSize_Params {
		public RECT rect1;
		public RECT rect2;
		public RECT rect3;
		public WINDOWPOS PWindowPos;
	}

	[StructLayout(LayoutKind.Sequential)]
	struct RECT {
		public int left;
		public int top;
		public int right;
		public int bottom;
	}

	[StructLayout(LayoutKind.Sequential)]
	struct WINDOWPOS {
		public IntPtr hwnd;
		public IntPtr hwndInsertAfter;
		public int x;
		public int y;
		public int cx;
		public int cy;
		public uint flags;

	}

	public enum WindowMsg : int{
		WM_NULL = 0x00,
		WM_CREATE = 0x01,
		WM_DESTROY = 0x02,
		WM_MOVE = 0x03,
		WM_SIZE = 0x05,
		WM_ACTIVATE = 0x06,
		WM_SETFOCUS = 0x07,
		WM_KILLFOCUS = 0x08,
		WM_ENABLE = 0x0A,
		WM_SETREDRAW = 0x0B,
		WM_SETTEXT = 0x0C,
		WM_GETTEXT = 0x0D,
		WM_GETTEXTLENGTH = 0x0E,
		WM_PAINT = 0x0F,
		WM_CLOSE = 0x10,
		WM_QUERYENDSESSION = 0x11,
		WM_QUIT = 0x12,
		WM_QUERYOPEN = 0x13,
		WM_ERASEBKGND = 0x14,
		WM_SYSCOLORCHANGE = 0x15,
		WM_ENDSESSION = 0x16,
		WM_SYSTEMERROR = 0x17,
		WM_SHOWWINDOW = 0x18,
		WM_CTLCOLOR = 0x19,
		WM_WININICHANGE = 0x1A,
		WM_SETTINGCHANGE = 0x1A,
		WM_DEVMODECHANGE = 0x1B,
		WM_ACTIVATEAPP = 0x1C,
		WM_FONTCHANGE = 0x1D,
		WM_TIMECHANGE = 0x1E,
		WM_CANCELMODE = 0x1F,
		WM_SETCURSOR = 0x20,
		WM_MOUSEACTIVATE = 0x21,
		WM_CHILDACTIVATE = 0x22,
		WM_QUEUESYNC = 0x23,
		WM_GETMINMAXINFO = 0x24,
		WM_PAINTICON = 0x26,
		WM_ICONERASEBKGND = 0x27,
		WM_NEXTDLGCTL = 0x28,
		WM_SPOOLERSTATUS = 0x2A,
		WM_DRAWITEM = 0x2B,
		WM_MEASUREITEM = 0x2C,
		WM_DELETEITEM = 0x2D,
		WM_VKEYTOITEM = 0x2E,
		WM_CHARTOITEM = 0x2F,

		WM_SETFONT = 0x30,
		WM_GETFONT = 0x31,
		WM_SETHOTKEY = 0x32,
		WM_GETHOTKEY = 0x33,
		WM_QUERYDRAGICON = 0x37,
		WM_COMPAREITEM = 0x39,
		WM_COMPACTING = 0x41,
		WM_WINDOWPOSCHANGING = 0x46,
		WM_WINDOWPOSCHANGED = 0x47,
		WM_POWER = 0x48,
		WM_COPYDATA = 0x4A,
		WM_CANCELJOURNAL = 0x4B,
		WM_NOTIFY = 0x4E,
		WM_INPUTLANGCHANGEREQUEST = 0x50,
		WM_INPUTLANGCHANGE = 0x51,
		WM_TCARD = 0x52,
		WM_HELP = 0x53,
		WM_USERCHANGED = 0x54,
		WM_NOTIFYFORMAT = 0x55,
		WM_CONTEXTMENU = 0x7B,
		WM_STYLECHANGING = 0x7C,
		WM_STYLECHANGED = 0x7D,
		WM_DISPLAYCHANGE = 0x7E,
		WM_GETICON = 0x7F,
		WM_SETICON = 0x80,

		WM_NCCREATE = 0x81,
		WM_NCDESTROY = 0x82,
		WM_NCCALCSIZE = 0x83,
		WM_NCHITTEST = 0x84,
		WM_NCPAINT = 0x85,
		WM_NCACTIVATE = 0x86,
		WM_GETDLGCODE = 0x87,
		WM_NCMOUSEMOVE = 0xA0,
		WM_NCLBUTTONDOWN = 0xA1,
		WM_NCLBUTTONUP = 0xA2,
		WM_NCLBUTTONDBLCLK = 0xA3,
		WM_NCRBUTTONDOWN = 0xA4,
		WM_NCRBUTTONUP = 0xA5,
		WM_NCRBUTTONDBLCLK = 0xA6,
		WM_NCMBUTTONDOWN = 0xA7,
		WM_NCMBUTTONUP = 0xA8,
		WM_NCMBUTTONDBLCLK = 0xA9,

		WM_KEYFIRST = 0x100,
		WM_KEYDOWN = 0x100,
		WM_KEYUP = 0x101,
		WM_CHAR = 0x102,
		WM_DEADCHAR = 0x103,
		WM_SYSKEYDOWN = 0x104,
		WM_SYSKEYUP = 0x105,
		WM_SYSCHAR = 0x106,
		WM_SYSDEADCHAR = 0x107,
		WM_KEYLAST = 0x108,

		WM_IME_STARTCOMPOSITION = 0x10D,
		WM_IME_ENDCOMPOSITION = 0x10E,
		WM_IME_COMPOSITION = 0x10F,
		WM_IME_KEYLAST = 0x10F,

		WM_INITDIALOG = 0x110,
		WM_COMMAND = 0x111,
		WM_SYSCOMMAND = 0x112,
		WM_TIMER = 0x113,
		WM_HSCROLL = 0x114,
		WM_VSCROLL = 0x115,
		WM_INITMENU = 0x116,
		WM_INITMENUPOPUP = 0x117,
		WM_MENUSELECT = 0x11F,
		WM_MENUCHAR = 0x120,
		WM_ENTERIDLE = 0x121,

		WM_CTLCOLORMSGBOX = 0x132,
		WM_CTLCOLOREDIT = 0x133,
		WM_CTLCOLORLISTBOX = 0x134,
		WM_CTLCOLORBTN = 0x135,
		WM_CTLCOLORDLG = 0x136,
		WM_CTLCOLORSCROLLBAR = 0x137,
		WM_CTLCOLORSTATIC = 0x138,

		WM_MOUSEFIRST = 0x200,
		WM_MOUSEMOVE = 0x200,
		WM_LBUTTONDOWN = 0x201,
		WM_LBUTTONUP = 0x202,
		WM_LBUTTONDBLCLK = 0x203,
		WM_RBUTTONDOWN = 0x204,
		WM_RBUTTONUP = 0x205,
		WM_RBUTTONDBLCLK = 0x206,
		WM_MBUTTONDOWN = 0x207,
		WM_MBUTTONUP = 0x208,
		WM_MBUTTONDBLCLK = 0x209,
		WM_MOUSEWHEEL = 0x20A,
		WM_MOUSEHWHEEL = 0x20E,

		WM_PARENTNOTIFY = 0x210,
		WM_ENTERMENULOOP = 0x211,
		WM_EXITMENULOOP = 0x212,
		WM_NEXTMENU = 0x213,
		WM_SIZING = 0x214,
		WM_CAPTURECHANGED = 0x215,
		WM_MOVING = 0x216,
		WM_POWERBROADCAST = 0x218,
		WM_DEVICECHANGE = 0x219,

		WM_MDICREATE = 0x220,
		WM_MDIDESTROY = 0x221,
		WM_MDIACTIVATE = 0x222,
		WM_MDIRESTORE = 0x223,
		WM_MDINEXT = 0x224,
		WM_MDIMAXIMIZE = 0x225,
		WM_MDITILE = 0x226,
		WM_MDICASCADE = 0x227,
		WM_MDIICONARRANGE = 0x228,
		WM_MDIGETACTIVE = 0x229,
		WM_MDISETMENU = 0x230,
		WM_ENTERSIZEMOVE = 0x231,
		WM_EXITSIZEMOVE = 0x232,
		WM_DROPFILES = 0x233,
		WM_MDIREFRESHMENU = 0x234,

		WM_IME_SETCONTEXT = 0x281,
		WM_IME_NOTIFY = 0x282,
		WM_IME_CONTROL = 0x283,
		WM_IME_COMPOSITIONFULL = 0x284,
		WM_IME_SELECT = 0x285,
		WM_IME_CHAR = 0x286,
		WM_IME_KEYDOWN = 0x290,
		WM_IME_KEYUP = 0x291,

		WM_MOUSEHOVER = 0x2A1,
		WM_NCMOUSELEAVE = 0x2A2,
		WM_MOUSELEAVE = 0x2A3,

		WM_CUT = 0x300,
		WM_COPY = 0x301,
		WM_PASTE = 0x302,
		WM_CLEAR = 0x303,
		WM_UNDO = 0x304,

		WM_RENDERFORMAT = 0x305,
		WM_RENDERALLFORMATS = 0x306,
		WM_DESTROYCLIPBOARD = 0x307,
		WM_DRAWCLIPBOARD = 0x308,
		WM_PAINTCLIPBOARD = 0x309,
		WM_VSCROLLCLIPBOARD = 0x30A,
		WM_SIZECLIPBOARD = 0x30B,
		WM_ASKCBFORMATNAME = 0x30C,
		WM_CHANGECBCHAIN = 0x30D,
		WM_HSCROLLCLIPBOARD = 0x30E,
		WM_QUERYNEWPALETTE = 0x30F,
		WM_PALETTEISCHANGING = 0x310,
		WM_PALETTECHANGED = 0x311,

		WM_HOTKEY = 0x312,
		WM_PRINT = 0x317,
		WM_PRINTCLIENT = 0x318,

		WM_HANDHELDFIRST = 0x358,
		WM_HANDHELDLAST = 0x35F,
		WM_PENWINFIRST = 0x380,
		WM_PENWINLAST = 0x38F,
		WM_COALESCE_FIRST = 0x390,
		WM_COALESCE_LAST = 0x39F,
		WM_DDE_FIRST = 0x3E0,
		WM_DDE_INITIATE = 0x3E0,
		WM_DDE_TERMINATE = 0x3E1,
		WM_DDE_ADVISE = 0x3E2,
		WM_DDE_UNADVISE = 0x3E3,
		WM_DDE_ACK = 0x3E4,
		WM_DDE_DATA = 0x3E5,
		WM_DDE_REQUEST = 0x3E6,
		WM_DDE_POKE = 0x3E7,
		WM_DDE_EXECUTE = 0x3E8,
		WM_DDE_LAST = 0x3E8,

		WM_USER = 0x400,
		WM_APP = 0x8000,
	}

	public enum WindowStyle : int {
		WS_OVERLAPPED = 0x00000000,
		WS_POPUP = unchecked((int)0x80000000),
		WS_CHILD = 0x40000000,
		WS_MINIMIZE = 0x20000000,
		WS_VISIBLE = 0x10000000,
		WS_DISABLED = 0x08000000,
		WS_CLIPSIBLINGS = 0x04000000,
		WS_CLIPCHILDREN = 0x02000000,
		WS_MAXIMIZE = 0x01000000,
		WS_CAPTION = 0x00C00000,
		WS_BORDER = 0x00800000,
		WS_DLGFRAME = 0x00400000,
		WS_VSCROLL = 0x00200000,
		WS_HSCROLL = 0x00100000,
		WS_SYSMENU = 0x00080000,
		WS_THICKFRAME = 0x00040000,
		WS_GROUP = 0x00020000,
		WS_TABSTOP = 0x00010000,
		WS_MINIMIZEBOX = 0x00020000,
		WS_MAXIMIZEBOX = 0x00010000,
		WS_TILED = WS_OVERLAPPED,
		WS_ICONIC = WS_MINIMIZE,
		WS_SIZEBOX = WS_THICKFRAME,
		WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
		WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
                                WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX),
		WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),
		WS_CHILDWINDOW = (WS_CHILD),

	}

	public enum ClassStyle {
		CS_DropSHADOW = 0x20000  //实现窗体阴影
	}

	public class Win32 {
		public const int HWND_BOTTOM = 1;
		public const int HWND_NOTOPMOST = -2;
		public const int HWND_TOP = 0;
		public const int HWND_TOPMOST = -1;

		public const int SWP_ASYNCWINDOWPOS = 0x4000;
		public const int SWP_DEFERERASE = 0x2000;
		public const int SWP_DRAWFRAME = 0x0020;
		public const int SWP_FRAMECHANGED = 0x0020;
		public const int SWP_HIDEWINDOW = 0x0080;
		public const int SWP_NOACTIVATE = 0x0010;
		public const int SWP_NOCOPYBITS = 0x0100;
		public const int SWP_NOMOVE = 0x0002;
		public const int SWP_NOOWNERZORDER = 0x0200;
		public const int SWP_NOREDRAW = 0x0008;
		public const int SWP_NOREPOSITION = 0x0200;
		public const int SWP_NOSENDCHANGING = 0x0400;
		public const int SWP_NOSIZE = 0x0001;
		public const int SWP_NOZORDER = 0x0004;
		public const int SWP_SHOWWINDOW = 0x0040;

		public const int SW_SHOWNOACTIVATE = 4;

		public const Int32 ULW_COLORKEY  =   0x00000001;
		public const Int32 ULW_ALPHA  =   0x00000002;
		public const Int32 ULW_OPAQUE  =   0x00000004;

		public const byte AC_SRC_OVER  =   0x00;
		public const byte AC_SRC_ALPHA  =   0x01;

		const int GWL_EXSTYLE=-20;
		const int WS_EX_TRANSPARENT=0x20;
		const int WS_EX_LAYERED=0x80000;
		const int LWA_ALPHA=2;

		public const int WM_SysCommand  =   0x0112;
		public const int SC_MOVE  =   0xF012;

		public const int SC_MAXIMIZE  =   61488;
		public const int SC_MINIMIZE  =   61472;

		public const int WM_MOVE = 0x0003;
		public const int WM_MOVING = 0x0216;

		public const int WM_ERASEBKGND = 0x0014;
		public const int WM_LBUTTONDOWN = 0x0201;
		public const int WM_LBUTTONUP = 0x0202;
		public const int WM_LBUTTONDBLCLK = 0x0203;
		public const int WM_WINDOWPOSCHANGING = 0x46;
		public const int WM_PAINT = 0xF;
		public const int WM_CREATE = 0x0001;
		public const int WM_ACTIVATE = 0x0006;
		public const int WM_NCCREATE = 0x0081;
		public const int WM_NCCALCSIZE = 0x0083;
		public const int WM_NCPAINT = 0x0085;
		public const int WM_NCACTIVATE = 0x0086;
		public const int WM_NCLBUTTONDOWN = 0x00A1;
		public const int WM_NCLBUTTONUP = 0x00A2;
		public const int WM_NCLBUTTONDBLCLK = 0x00A3;
		public const int WM_NCMOUSEMOVE = 0x00A0;

		public const int WM_NCHITTEST = 0x0084;

		public const int HTLEFT = 10;
		public const int HTRIGHT = 11;
		public const int HTTOP = 12;
		public const int HTTOPLEFT = 13;
		public const int HTTOPRIGHT = 14;
		public const int HTBOTTOM = 15;
		public const int HTBOTTOMLEFT = 0x10;
		public const int HTBOTTOMRIGHT = 17;
		public const int HTCAPTION = 2;
		public const int HTCLIENT = 1;

		public const int WM_FALSE = 0;
		public const int WM_TRUE = 1;

		public enum Bool {
			False  =   0,
			True
		} ;


		[StructLayout(LayoutKind.Sequential)]
		public struct Point {
			public Int32 x;
			public Int32 y;

			public Point(Int32 x, Int32 y) { this.x  =  x; this.y  =  y; }
		}


		[StructLayout(LayoutKind.Sequential)]
		public struct Size {
			public Int32 cx;
			public Int32 cy;

			public Size(Int32 cx, Int32 cy) { this.cx  =  cx; this.cy  =  cy; }
		}


		[StructLayout(LayoutKind.Sequential, Pack  =   1)]
		struct ARGB {
			public byte Blue;
			public byte Green;
			public byte Red;
			public byte Alpha;
		}


		[StructLayout(LayoutKind.Sequential, Pack  =   1)]
		public struct BLENDFUNCTION {
			public byte BlendOp;
			public byte BlendFlags;
			public byte SourceConstantAlpha;
			public byte AlphaFormat;
		}

		[DllImport("User32.dll", CharSet = CharSet.Auto)]
		public static extern int InvertRect(IntPtr hdc, ref Rectangle lprc);

		[DllImport("User32.dll", CharSet = CharSet.Auto)]
		public static extern int DrawFocusRect(IntPtr hdc, ref Rectangle lprc);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern IntPtr SetActiveWindow(IntPtr hwnd);//设置活动窗体

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern IntPtr ShowWindow(IntPtr hWnd, int nCmdShow);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		public static extern int GetClassLong(IntPtr hwnd, int nIndex);

		[DllImport("user32.dll", EntryPoint = "AnimateWindow")]
		public static extern bool AnimateWindow(IntPtr handle, int ms, int flags);

		[DllImport("gdi32.dll")]
		public static extern int CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3);

		[DllImport("user32.dll")]
		public static extern int SetWindowRgn(IntPtr hwnd, int hRgn, Boolean bRedraw);

		[DllImport("gdi32.dll", EntryPoint = "DeleteObject", CharSet = CharSet.Ansi)]
		public static extern int DeleteObject(int hObject);

		[DllImport("user32.dll")]
		public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);


		[DllImport("user32.dll", ExactSpelling  =   true, SetLastError  =   true)]
		public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref  Point pptDst, ref  Size psize, IntPtr hdcSrc, ref  Point pprSrc, Int32 crKey, ref  BLENDFUNCTION pblend, Int32 dwFlags);

		[DllImport("user32.dll", ExactSpelling  =   true, SetLastError  =   true)]
		public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, IntPtr pptDst, IntPtr psize, IntPtr hdcSrc, IntPtr pprSrc, Int32 crKey, ref  BLENDFUNCTION pblend, Int32 dwFlags);

		[DllImport("user32.dll", ExactSpelling  =   true, SetLastError  =   true)]
		public static extern IntPtr GetDC(IntPtr hWnd);

		[DllImport("user32.dll", ExactSpelling  =   true)]
		public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
		public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError  =   true)]
		public static extern Bool DeleteDC(IntPtr hdc);

		[DllImport("gdi32.dll", ExactSpelling = true)]
		public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);

		[DllImport("gdi32.dll", ExactSpelling = true, SetLastError  =   true)]
		public static extern Bool DeleteObject(IntPtr hObject);

		[DllImport("user32.dll", EntryPoint = "SendMessage")]
		public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);

		[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
		public static extern int ReleaseCapture();

		[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
		public static extern IntPtr CreateBitmap(int nWidth, int nHeight, int cPlanes, int cBitsPeral, IntPtr lpvBits);

		[DllImport("user32.dll", EntryPoint="GetWindowLong")]
		public static extern long GetWindowLong(IntPtr hwnd, int nIndex);

		[DllImport("user32.dll", EntryPoint="SetWindowLong")]
		public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);

		[DllImport("user32.dll", EntryPoint="SetLayeredWindowAttributes")]
		public static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags);


	}
}
